<?php
namespace Admin\Controller;
use Think\Controller;
class IndexController extends Controller {
    public function index(){
        echo 334;
    }

    public function upload()
    {
		$config = array(
            'maxSize'    =>  3145728,
            'rootPath'   =>    './Uploads/',
            'savePath'   =>    '',
            'saveName'   =>    array('uniqid',''),
            'exts'       =>    array('jpg', 'gif', 'png', 'jpeg'),
            'autoSub'    =>    true,
            'subName'    =>    array('date','Ymd'),
		);
        $upload = new \Think\Upload($config);// 实例化上传类

        // 上传单个文件 
        $info   =   $upload->uploadOne($_FILES['file']); // $info['savename'] ......

        if(!$info) {// 上传错误提示错误信息
            $this->error($upload->getError());
        }else{// 上传成功
            //$this->success('上传成功！');
            echo $info['savepath'].$info['savename'];  //单文件上传成功 返回文件信息
        }        
    }

    //图片上传url
	function upload_remote() {
		//A("Common/Util")->file();
	    A("Common/Util")->file_remote();
    }
    
    /**
	 * 上传图片到远端 
	 */
	function upfile_to_remote() {

	    $upload_path = C("UPLOAD_ROOT_PATH");

	    $type = in_array($type, array('image','audio')) ? $type : 'image';
        $file = $_FILES['file'];
        $ext = pathinfo($file['name'], PATHINFO_EXTENSION);
        $ext = strtolower($ext);
        //$setting = $_W['upload'][$type];
        $harmtype = array('asp', 'php', 'jsp', 'js', 'css', 'php3', 'php4', 'php5', 'ashx', 'aspx', 'exe', 'cgi');
        if (!in_array(strtolower($ext), $setting['extentions']) || in_array(strtolower($ext), $harmtype)) {
            $result = error(-3, '不允许上传此类文件'.$type);
            die(json_encode($result));
        }
        if (!empty($setting['limit']) && $setting['limit'] * 1024 < filesize($file['tmp_name'])) {
            $result = error(-4, "上传的文件超过大小限制，请上传小于 {$setting['limit']}k 的文件");
            die(json_encode($result));
        }
        
        $url = "http://wx.hnlyrs.gov.cn:8668/thinkphp_3.2.3_full/myweixin/index.php?s=/weixin/utility/uploadimg_amy";
        $s = $this->curl_upload($url, $file['name'],$file['tmp_name'],"");

        $result = json_decode($s);
        
        if(!$result->status){
            die(json_encode(error(-3, '上传出错')));
        }

    }
    
}